<template>
	<view class="">
		<NavBar :title="navTitle" :isShowLeftBtn="true">
		</NavBar>
	</view>
	<view class="" v-if="isShowPage">
		<view class="" style="background: white;">
			<up-swiper :list="imgList" @change="e => currentNum = e.current" :autoplay="true"
				indicatorStyle="right: 20px" height="220">
				<template #indicator>
					<view class="indicator-num">
						<view class="">
							<text class=" f_24_0"
								style="color: #F5F5F5;">{{ currentNum + 1 }}/{{ imgList.length }}</text>
						</view>
					</view>
				</template>
			</up-swiper>
		</view>
		<view class="content" :style="{minHeight:contentHeight}">
			<view class="main">
				<view class="row1 m_b_20">
					<view class="m_b_22 flex_both">
						<view class="">
							<text class="f_30_0_b">
								{{storeDetail.shop_name}}
							</text>
						</view>
						<view class="" style="padding: 0 16rpx;position: relative;" @click="toMsg">
							<view class="">
								<up-image :show-loading="true" src="/static/images/my/detail_message.png" width="42rpx"
									height="38rpx"></up-image>
							</view>
							<view class="">
								<up-badge bgColor="#F74515" color="#ffffff" shape="circle" max="99"
									:value="storeDetail.msgCount" :absolute="true" :offset="[-10,1]"></up-badge>
							</view>
						</view>
					</view>
					<view class="">
						<view class="flex" style="align-items: flex-start;">
							<view class="m_r_10">
								<text class="f_26_0_b">
									评分{{storeDetail.score}}
								</text>
							</view>
							<view class="m_t_4">
								<up-rate v-model="storeDetail.score"
									active-color="linear-gradient(to bottom, #FFFF59, #F9B900);"
									inactive-color="#b2b2b2" gutter="5" size="20" disabled></up-rate>
							</view>
						</view>
					</view>
					<view class="hr m_t_22 m_b_32">

					</view>
					<view class="">
						<view class="flex">
							<view class="m_r_12 m_b_6">
								<up-image :show-loading="true" src="/static/images/index/clock_icon.png" width="28rpx"
									height="28rpx"></up-image>
							</view>
							<view class="">
								<text class="f_24_0" style="color: #737272;">
									营业时间：{{storeDetail.begin_hour}} - {{storeDetail.end_hour}}
								</text>
							</view>
							<view class="f_26_0 m_l_12 m_r_12 m_t_6" style="color: #737272;">
								<text>
									|
								</text>
							</view>
							<view class="">
								<view class="" v-if="storeDetail.is_stop">
									<text class="f_24_0" style="color: #737272;"
										v-if="storeDetail.is_yingye">
										暂停营业
									</text>
								</view>
								<view class="" v-else>
									<text class="f_24_0" style="color: #FE450C;"
										v-if="storeDetail.is_yingye">
										营业中
									</text>
									<text class="f_24_0" style="color: #FA7B27;" v-else>
										已打烊
									</text>
								</view>
							</view>
						</view>
					</view>
					<view class="hr m_t_28 m_b_28">

					</view>
					<view class="flex_both">
						<view class="">
							<view class="m_b_16">
								<text class="f_28_0_b">
									{{storeDetail.shop_name}}
								</text>
							</view>
							<view class="flex" style="align-items: flex-start;">
								<view class="m_r_6 m_t_2 m_l_6" style="width: 28rpx; height: 28rpx;flex-shrink: 0;">
									<up-image :show-loading="true" src="/static/images/index/position_icon.png"
										width="18rpx" height="24rpx"></up-image>
								</view>
								<view class="" style="width: 450rpx;">
									<text class="f_24_0" style="color: #737272;">
										{{storeDetail.address}}
									</text>

								</view>
							</view>
						</view>
						<view class="" @click="toOpenlocation(storeDetail)">
							<view class=""
								style="width: 76rpx;height: 76rpx; border-radius: 50%;display: flex;align-items: center;justify-content: center;background: #FBF1EC;">
								<view class="m_t_4">
									<up-icon name="/static/images/index/detail_dh.png" size="18"
										color="#F7480B"></up-icon>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="row2 m_b_20">
					<view class="m_b_36">
						<text class="f_30_0_b">
							{{storeDetail.shop_name}}
						</text>
					</view>
					<view class="">
						<up-parse :content="storeDetail.desc"></up-parse>
					</view>
				</view>
				<view class="row3">
					<view class="row3_list">
						<view class="row3_item flex_both" v-for="(item,index) in row3List" :key="index"
							@click="onClickRow3Item(item)">
							<view class="">
								<text class="f_28_0">
									{{item.label}}
								</text>
							</view>
							<view class="">
								<up-image :show-loading="true" src="/static/images/my/arrow_right.png" width="17rpx"
									height="34rpx"></up-image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="">
			<up-popup :show="editPopupShow" mode="center" round="10" :safeAreaInsetBottom="false">
				<view class="popup_box" style="height: 492rpx;">
					<view class="popup_title m_b_46">
						<text class="f_30_0_b">
							修改营业时间
						</text>
					</view>
					<view class="popup_close" @click="onEditPopupClose">
						<up-icon name="close" color="#000000" size="17"></up-icon>
					</view>
					<view class="m_b_32 flex">
						<text class="f_28_0" style="display: inline-block; width: 170rpx;">
							开始时间：
						</text>
						<up-datetime-picker hasInput :show="beginTimeShow" v-model="editForm.begin_hour" mode="time"
							confirmColor="#F76D11" @confirm="beginTimeShow = false"
							@cancel="beginTimeShow = false"></up-datetime-picker>
					</view>
					<view class="m_b_32 flex">
						<text class="f_28_0" style="display: inline-block; width: 170rpx;">
							结束时间：
						</text>
						<up-datetime-picker hasInput :show="endTimeShow" v-model="editForm.end_hour" mode="time"
							confirmColor="#F76D11" @confirm="endTimeShow = false"
							@cancel="endTimeShow = false"></up-datetime-picker>
					</view>
					<view class="m_b_80 flex">
						<text class="f_28_0" style="display: inline-block; width: 170rpx;">
							暂停营业：
						</text>
						<view class="m_t_6">
							<up-switch v-model="editForm.is_stop" size="18" active-color="#F76D11"
								inactiveColor="#999999" :activeValue="1" :inactiveValue="0"></up-switch>
						</view>
					</view>
					<view class="popup_btn" @click="onEditPopupOk">
						<view class="m_b_10">
							<text class="f_24_f">
								确定
							</text>
						</view>
					</view>
				</view>
			</up-popup>

		</view>
	</view>
</template>
<script setup lang="ts">
	import { ref, reactive, getCurrentInstance } from "vue";
	import { onLoad, onShow } from "@dcloudio/uni-app";
	import NavBar from "@/components/navbar.vue"
	const { proxy } = getCurrentInstance()
	const contentHeight = ref('100vh')
	const statusBarHeight = ref(88)
	const sId = ref(0)
	const isShowPage = ref(false)
	const navTitle = ref('详情')
	onLoad((e) => {
		uni.getSystemInfo({
			success: function (info) {
				statusBarHeight.value = (info.statusBarHeight + 44) * 2
				contentHeight.value = `calc(100vh - ${statusBarHeight.value + 80 + 402}rpx)`
			}
		});
		sId.value = e.id
	})
	onShow(() => {
		getMyDetail()
	})
	const storeDetail = ref({})
	const getMyDetail = async () => {
		let res = await proxy.$http('my.getMyDetail', { shop_id: sId.value })
		let data = res.data
		navTitle.value = data.shop_name
		storeDetail.value = data
		if (data.shop_images) {
			imgList.value = data.shop_images.split(',')
		}
		initList()
		if (storeDetail.value.parent_shop_id > 0) {
			row3List.value.splice(4, 1)
		}
		editForm.value.begin_hour = data.begin_hour
		editForm.value.end_hour = data.end_hour
		editForm.value.is_stop = data.is_stop
		isShowPage.value = true

	}
	const imgList = ref(['https://cdn.uviewui.com/uview/swiper/swiper3.png',
		'https://cdn.uviewui.com/uview/swiper/swiper2.png',
		'https://cdn.uviewui.com/uview/swiper/swiper1.png',])
	// 轮播
	const currentNum = ref(0)

	const row3List = ref([

	])
	const initList = () => {
		row3List.value = [{ label: '我的二维码', url: `/pages/my/storeCode` },
		{ label: '洗车记录', url: '/pages/my/washLog' },
		{ label: '结算数据', url: '/pages/my/settlementData' },
		{ label: '结算记录', url: '/pages/my/storeSettlementLog' },
		{ label: '分店管理', url: '/pages/my/branchManage' },
		{ label: '修改营业时间', url: 'edit' },]
	}
	const onClickRow3Item = (e) => {
		if (!e.url) return
		if (e.url == 'edit') {
			showEditPopup()
			return
		}
		uni.navigateTo({
			url: e.url + `?id=${storeDetail.value.shop_id}&name=${storeDetail.value.shop_name}`
		})
	}
	// 修改营业时间
	const editForm = ref({
		begin_hour: '00:00',
		end_hour: '00:00',
		is_stop: 0
	})

	const editPopupShow = ref(false)
	const showEditPopup = () => {
		editPopupShow.value = true
	}
	const onEditPopupClose = () => {
		editPopupShow.value = false
	}
	const onEditPopupOk = () => {

		if (handleTime(editForm.value.begin_hour) > handleTime(editForm.value.end_hour)) {
			uni.$u.toast('开始时间不大于结束时间')
			return
		}
		editYingyeTime()
		editPopupShow.value = false
	}
	const handleTime = (time) => {
		let h = time.split(':')[0]
		let m = time.split(':')[1]
		return parseInt(h) * 60 + parseInt(m)
	}
	const editYingyeTime = async () => {
		let res = await proxy.$http('my.editYingyeTime', { ...editForm.value })
		if (res.code == 1) {
			uni.$u.toast('修改成功')
			setTimeout(() => {
			
				getMyDetail()
			})
		}
	}
	// 选择器
	const beginTimeShow = ref(false)
	const endTimeShow = ref(false)
	// 消息
	const type = ref('warning');
	const toMsg = () => {
		console.log(1);
		uni.navigateTo({
			url: `/pages/my/examineMessage?id=${storeDetail.shop_id}`
		})
	}


	const toOpenlocation = (e) => {
		uni.openLocation({
			// 目标位置的经纬度
			latitude: parseFloat(e.lat),
			longitude: parseFloat(e.lng),
			// 目标位置的名称
			name: e.shop_name,
			// 目标位置的详细地址
			address: e.address,
			// 地图缩放比例
			scale: 18,
			// 调用成功时的回调函数
			success: function (res) {
				console.log('调用成功：', res)
			},
			// 调用失败时的回调函数
			fail: function (res) {
				console.log('调用失败：', res)
			},
			// 调用完成时的回调函数
			complete: function (res) {
				console.log('调用完成：', res)
			}
		})
	}
</script>
<style lang="scss" scoped>
	.indicator-num {
		text-align: center;
		width: 86rpx;
		height: 43rpx;
		padding-bottom: 4rpx;
		background: rgba(0, 0, 0, 0.5);
		border-radius: 22rpx;
		// opacity: 0.5;
	}

	.content {
		background: #F7F8FC;
		padding: 20rpx 0;
		padding-top: 0;
		padding-bottom: 64rpx;

		.row1 {
			padding: 30rpx 20rpx;
			padding-top: 34rpx;
			background: #ffffff;
			box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
		}

		.row2 {
			background: #ffffff;
			box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
			padding: 36rpx 22rpx;

		}

		.row3 {
			padding-bottom: 50rpx;

			.row3_list {
				.row3_item {
					height: 87rpx;
					padding: 0 20rpx;
					background: #FFFFFF;
					box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
					border-radius: 5rpx;
					margin-bottom: 18rpx;
				}
			}
		}


	}

	::v-deep.uicon-star-fill {
		background: linear-gradient(to bottom, #FFFF59, #F9B900);
		/*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
		-webkit-background-clip: text;
		/*将设置的背景颜色限制在文字中*/
		-webkit-text-fill-color: transparent;
		/*给文字设置成透明*/
	}

	.popup_box {
		width: 586rpx;
		height: 291rpx;
		padding: 46rpx;
		padding-top: 36rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		position: relative;

		.popup_title {
			text-align: center;
		}

		.popup_close {
			position: absolute;
			top: 18rpx;
			right: 18rpx;
			padding: 6rpx;
		}

		.popup_btn {
			margin: 0 auto;
			width: 261rpx;
			height: 63rpx;
			background: #F93F1A;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>